package spring.my_aop;

import java.lang.reflect.Proxy;


public class DyProxy<T> {

    public <T> T getProxyObject(Class<T> tClass) throws IllegalAccessException, InstantiationException {
        AbstractPojo t = (AbstractPojo) tClass.newInstance();
        PojoProxyInvocationHandler<AbstractPojo> pojoProxyInvocationHandler = new PojoProxyInvocationHandler<>(t);
        return (T) Proxy.newProxyInstance(tClass.getClassLoader(), tClass.getInterfaces(), pojoProxyInvocationHandler);
    }

//    public <T> T getProxyObject(Class<T> clazz) throws IllegalAccessException, InstantiationException {
//        final T t = clazz.newInstance();
//        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(),
//                (proxy, method, args) -> {
//
//                    T result;
//                    return method.invoke(t, args);
//                });
//    }
}
